home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -websites- / wirenet / files / wirenet151.lzx / Updates / Connect next >
Text File  |  2013-09-22  |  10KB  |  287 lines

  1. /* $VER: Connect 1.51  (30.10.96) (c) Neil Bothwick */
  2. /*                                                  */
  3. /* Connects your Amiga to the Internet, optionally  */
  4. /* fetching news or mail and logging off again      */
  5. /* :
  6.     Name
  7.         Connect
  8.  
  9.     Usage
  10.         Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]
  11.  
  12.     Options
  13.         None:       Connects to Internet
  14.         MAIL:       Connects to Internet and fetches mail
  15.         NEWS:       Connects to Internet and fetches news and mail
  16.         AUTOMAIL:   Connects to Internet, fetches mail and disconnects
  17.         AUTONEWS:   Connects to Internet, fetches news and mail and disconnects
  18.         OFF:        Disconnects from Internet
  19.         AUTOOFF:    Disconnects from Internet after waiting for news and mail to finish
  20.  
  21. */
  22. ;;
  23. /* :These are specific to your setup */
  24.  
  25. DevName    = 'DEVS:Networks/ppp.device'                             /* Your network device */
  26. DevUnit    = 0                                                      /* its unit number */
  27. Interface  = 'ppp'||DevUnit                                         /* Interface name */
  28. ;;
  29. /* :Don't change anything below here */
  30.  
  31. if ~show('L','rexxsupport.library') then                            /* Load the libraries */
  32.     if ~addlib('rexxsupport.library',0,-30) then exit
  33.  
  34. if ~show('L','rexxdossupport.library') then
  35.     if ~addlib('rexxdossupport.library',0,-30) then exit
  36.  
  37. if ~show('L','rexxreqtools.library') then
  38.     if ~addlib('rexxreqtools.library',0,-30) then exit
  39.  
  40. BinPath    = 'AmiTCP:bin/'                                          /* Paths to AmiTCP commands */
  41. ThorPath   = GetVar('Thor/ThorPath')
  42. Miami      = 'AmiTCP:Miami'
  43. StartNet   = BinPath||'StartNet'
  44. ifconfig   = BinPath||'ifconfig'
  45. route      = BinPath||'route'
  46. online     = BinPath||'online'
  47. offline    = BinPath||'offline'
  48. resolve    = BinPath||'resolve'
  49. SendEvents = BinPath||'SendEvents'
  50. GetMail    = BinPath||'Fetch Mail'
  51. GetNews    = BinPath||'Fetch All'
  52. LogPath    = 'UUSpool:Connect.log'
  53. SendProc   = ThorPath||'bin/SendTCP'                                /* CLI process names for news and mail */
  54. GetProc    = ThorPath||'bin/GetTCP'
  55. Unbatch    = BinPath||'ParseThor'
  56. ;;
  57. options results
  58. address command
  59. arg opt
  60.  
  61. /* :Main routine */
  62. if exists('ENV:Wirenet/UseMiami') then UseMiami = 1
  63. else UseMiami = 0
  64.  
  65. if GetVar('IPADDRESS') = '0.0.0.0' then AcctType = 'Dynamic'
  66. else AcctType = 'Static'
  67.  
  68. select
  69.     when opt = '' then call Connect
  70.     when opt = 'MAIL' then do
  71.         call Connect
  72.         call DoMail
  73.         end
  74.     when opt = 'NEWS' then do
  75.         call Connect
  76.         call DoNews
  77.         end
  78.     when opt = 'AUTOMAIL' then do
  79.         call Connect
  80.         call DoMail
  81.         call Auto
  82.         call Disconnect
  83.         end
  84.     when opt = 'AUTONEWS' then do
  85.         call Connect
  86.         call DoNews
  87.         call Auto
  88.         call Disconnect
  89.         end
  90.     when opt = 'OFF' then call Disconnect
  91.     when opt = 'AUTOOFF' then do
  92.         call Auto
  93.         call Disconnect
  94.         end
  95.     otherwise call BadArgs
  96.     end
  97. ;;
  98. exit
  99.  
  100. /* Procedures */
  101.  
  102. /* :Establish connection */
  103. Connect:
  104.     StartNet
  105.     if exists('AmiTCP:db/User-PreConnect') then address command 'AmiTCP:db/User-PreConnect'
  106.     if UseMiami = 0 then do
  107.         call MakeDialScript()
  108.         online Interface
  109.         if RC > 0 then call ConnectionFailed
  110.         ifconfig 'lo0 localhost'
  111.         ifconfig Interface '$ppp0IPLocal $ppp0IPRemote'
  112.         if AcctType = 'Dynamic' then do                             /* Set up for dynamic account */
  113.             address 'AMITCP' 'ADD HOST $ppp0IPLocal $HostName'
  114.             route 'add $ppp0IPLocal localhost'
  115.             end
  116.         route 'add default $ppp0IPRemote'
  117.         call WriteLog('Connection made to' GetVar('ppp0IPRemote'))
  118.         end
  119.     else do
  120.         address 'MIAMI.1' 'ONLINE'
  121.         address 'MIAMI.1' 'ISONLINE'
  122.         if RC = 0 then call ConnectionFailed
  123.         call WriteLog('Connection made')
  124.         end
  125.     'SetEnv NetState Online'
  126.     if exists('AmiTCP:db/User-PostConnect') then address command 'AmiTCP:db/User-PostConnect'
  127.     'run >UUSpool:SendEvents.debug' SendEvents
  128.     Wait 2
  129.     return
  130. ;;
  131. /* :Break connection */
  132. Disconnect:
  133.     if exists('AmiTCP:db/User-PreDisconnect') then address command 'AmiTCP:db/User-PreDisconnect'
  134.     if UseMiami = 0 then do
  135.         ifconfig interface 'down'
  136.         offline Interface
  137.         route 'delete >NIL: $ppp0IPLocal'
  138.         route 'delete >NIL: default'
  139.         end
  140.     else do
  141.         address 'MIAMI.1' 'OFFLINE'
  142.         end
  143.     call WriteLog('Connection closed')
  144.     'unsetenv FetchState'
  145.     'SetEnv NetState Offline'
  146.     Unbatch
  147.     if exists('AmiTCP:db/User-PostDisconnect') then address command 'AmiTCP:db/User-PostDisconnect'
  148.     return
  149. ;;
  150. /* :Start mail download */
  151. DoMail:
  152.     'run >NIL:' GetMail
  153.     call WriteLog('Mail download started')
  154.     return
  155. ;;
  156. /* :Start mail and news download */
  157. DoNews:
  158.     'Run >NIL:' GetNews
  159.     call WriteLog('News download started')
  160.     return
  161. ;;
  162. /* :Wait for mail and news processes to stop */
  163. Auto:
  164.     say 'Waiting for news/mail to finish'
  165.     Wait 4
  166.     call WaitToEnd(SendProc GetProc)
  167.     Wait 2
  168.     call WaitToEnd(SendProc GetProc)
  169.     return
  170. ;;
  171. /* :Give usage information */
  172. BadArgs:
  173.     say
  174.     say 'Usage: Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]'
  175.     say
  176.     say '       None:       Connects to Internet'
  177.     say '       MAIL:       Connects to Internet and fetches mail'
  178.     say '       NEWS:       Connects to Internet and fetches news and mail'
  179.     say '       AUTOMAIL    Connects to Internet, fetches mail and disconnects'
  180.     say '       AUTONEWS:   Connects to Internet, fetches news and mail and disconnects'
  181.     say '       OFF:        Disconnects from Internet'
  182.     say '       AUTOOFF:    Disconnects from Internet after waiting for news and mail to finish'
  183.     say
  184.     exit
  185.  ;;
  186. /* :Write line in logfile */
  187. WriteLog: procedure expose LogPath
  188.     parse arg msg
  189.     LogEntry = left(date('W'),3) date() time() msg
  190.     say LogEntry
  191.     if ~open(log,LogPath,'A') then do
  192.         if ~open(log,LogPath,'W') then return
  193.         end
  194.     call writeln(log,LogEntry)
  195.     call close(log)
  196.     return
  197. ;;
  198. /* :Wait for the specified process to finish */
  199. WaitToEnd: procedure
  200.     parse arg Processes
  201.  
  202.     procs = words(Processes)
  203.     do i = 1 to procs
  204.         parse var Processes Process.i Processes
  205.         end
  206.  
  207.     do until Busy = FALSE
  208.         Busy = FALSE
  209.         do i = 1 to procs
  210.             'Status >NIL: com='Process.i
  211.             if RC = 0 then do
  212.                 Busy = TRUE
  213.                 Wait 3
  214.                 end
  215.             end
  216.         end
  217.     return
  218. ;;
  219. /* :Report connection failure */
  220. ConnectionFailed:
  221.     call WriteLog('Connection attempt failed')
  222.     ExitMsg('Your internet connection has failed')
  223.     return
  224. ;;
  225. /* :Exit with message */
  226. ExitMsg:
  227.     parse arg ErrMsg
  228.     say(ErrMsg)
  229.     exit
  230.     return
  231. ;;
  232. /* :Create dialscript and ppp0.config */
  233. MakeDialScript:
  234.     /* Create DialScript */
  235.     if ~open('ds','ENV:Wirenet/DialScript','W') then call ExitMsg('Failed to create dialscript')
  236.     call writeln('ds','# Dialer Script (change to echo off if you do not want echoing)')
  237.     call writeln('ds','echo on')
  238.     call writeln('ds','abort "NO DIALTONE"')
  239.     call writeln('ds','redial "BUSY" "NO CARRIER" "NO ANSWER"')
  240.     call writeln('ds','redialdelay 300')
  241.     call writeln('ds','timeout 500')
  242.     call writeln('ds','# Initialise modem...')
  243.     call writeln('ds','send "'||GetVar('Wirenet/ModemInit')||'"')
  244.     call writeln('ds','wait "OK"')
  245.     call writeln('ds','delay 15')
  246.     call writeln('ds','# Send dial command...')
  247.     call writeln('ds','send "'||GetVar('Wirenet/ModemDial')||GetVar('Wirenet/PoPNum')||'"')
  248.     call writeln('ds','# ... and wait for connection.')
  249.     call writeln('ds','timeout 1600')
  250.     call writeln('ds','wait "CONNECT"')
  251.     if ~exists('ENV:Wirenet/UsePAP') then do
  252.         call writeln('ds','send ""')
  253.         call writeln('ds','# At login: prompt send nodename')
  254.         call writeln('ds','wait "ogin:"')
  255.         call writeln('ds','send "'||GetVar('NODENAME')||'"')
  256.         call writeln('ds','# At Password: prompt send password')
  257.         call writeln('ds','wait "assword:"')
  258.         call writeln('ds','echo off')
  259.         call writeln('ds','send "'||subword(GetVar('Wirenet/pap.config'),2)||'"')
  260.         call writeln('ds','echo on')
  261.         call writeln('ds','# Wait for Service: prompt and then send PPP')
  262.         call writeln('ds','wait "ervice:"')
  263.         call writeln('ds','send "PPP"')
  264.         call writeln('ds','# Wait for start string')
  265.         call writeln('ds','wait "MTU"')
  266.         call writeln('ds','send " "')
  267.         call writeln('ds','# Connected!')
  268.         end
  269.     call close('ds')
  270.  
  271.     /* Create PPP config file */
  272.     if ~open(pppcfg,'ENV:sana2/ppp0.config','w') then ExitMsg('Failed to create ppp configuration')
  273.     call writech(pppcfg,GetVar('Wirenet/ModemDev')' ')
  274.     call writech(pppcfg,GetVar('Wirenet/ModemSpeed')' ')
  275.     call writech(pppcfg,GetVar('IPADDRESS')' ')
  276.     call writech(pppcfg,'DialScript ENV:Wirenet/DialScript ')
  277.     call writech(pppcfg,'MTU='GetVar('Wirenet/MTU')' ')
  278.     call writech(pppcfg,GetVar('Wirenet/ppp.options'))
  279.     if exists('ENV:Wirenet/UsePAP') then call writech(pppcfg,' PAP=ENV:Wirenet/pap.config,'GetVar('NODENAME'))
  280.     if exists('ENV:Wirenet/DialWindow') then call writech(pppcfg,' DIALWINDOW ' GetVar('Wirenet/DialWindow'))
  281.     if exists('ENV:Wirenet/Gateway') then call writech(pppcfg,' REMOTEIP' GetVar('Wirenet/Gateway'))
  282.     call close(pppcfg)
  283.  
  284.     return
  285. ;;
  286.  
  287.